<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>商品售价设置</title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="./images/favicon.png" />

    <!-- <link href="./css/style.css" rel="stylesheet" /> -->

    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/jsgrid/jsgrid-theme.min.css" rel="stylesheet" />
    <link href="assets/css/lib/jsgrid/jsgrid.min.css" type="text/css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/helper.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">

    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.min.js"></script>
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>

    <script>
        //加载售货价格信息数据
        $(document).ready(function () {
            var requestObj = {};
            requestObj["requestService"] = "CommoditySellPriceService";
            requestObj["requestMethod"] = "selectAllCommoditySellPrice";
            var data = {};
            requestObj["data"] = data;
            var requestJson = JSON.stringify(requestObj);
            $.ajax({
                type: "POST",
                url: "http://192.168.70.135:80/api/",
                contentType: "application/json",
                data: requestJson,
                async: false,
                success: function (msg) {
                    window.db.clients = msg.data;
                    $("#jsGrid").jsGrid("loadData");
                }
            });
        });
    </script>

    <script>
        //点击确定按钮
        $(document).ready(function () {
            $("#submit").click(function () {
                if (window.selected) {
                    var requestObj = {};
                    requestObj["requestService"] = "CommoditySellPriceService";
                    requestObj["requestMethod"] = "updateCommoditySellPrice";
                    var data = {};
                    data["barCode"] = $("#barCode").val();
                    data["defaultSellPrice"] = $("#defaultSellPrice").val();
                    data["nowSellPrice"] = $("#nowSellPrice").val();
                    requestObj["data"] = data;
                    var requestJson = JSON.stringify(requestObj);
                    $.ajax({
                        type: "POST",
                        url: "http://192.168.70.135:80/api/",
                        contentType: "application/json",
                        data: requestJson,
                        async: false,
                        success: function (msg) {
                            location.reload();
                        }
                    });
                } else {
                    alert("需要先在左侧列表中选择项目");
                }
            });
        });
    </script>

</head>

<body>

    <script src="./common.js"></script>

    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div id="main-content">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="card">
                                <div class="card-header">
                                    <div class="card-title">
                                        <h4>商品列表 </h4>
                                    </div>
                                </div>
                                </br>
                                <div class="card-body">
                                    <div class="jsgrid-table-panel">
                                        <div id="jsGrid"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="card">
                                <div class="card-header">
                                    <div class="card-title">
                                        <h4>商品详情 </h4>
                                    </div>
                                </div>
                                <div class="card-body">
                                    <div class="basic-form">
                                        <div class="row">
                                            <div class="col-lg-4">
                                                <div class="form-group">
                                                    <label>商品条码</label>
                                                    <input id="barCode" type="text" class="form-control"
                                                        disabled="true">
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="form-group">
                                                    <label>商品名称</label>
                                                    <input id="productName" type="text" class="form-control"
                                                        disabled="true">
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="form-group">
                                                    <label>原价</label>
                                                    <input id="defaultSellPrice" type="number" class="form-control">
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="form-group">
                                                    <label>现价</label>
                                                    <input id="nowSellPrice" type="number" class="form-control">
                                                </div>
                                            </div>
                                        </div>
                                        <button type="button" class="btn btn-primary m-b-10 m-l-5"
                                            id="submit">确定</button>&nbsp;&nbsp;
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="footer">
                                    <div class="copyright">
                                        <p>Copyright © Designed &amp; Developed by <a href="#"
                                                target="_blank">Quixkit</a>
                                            2019</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <!-- nano scroller -->
        <script src="assets/js/lib/menubar/sidebar.js"></script>
        <script src="assets/js/lib/preloader/pace.min.js"></script>
        <!-- sidebar -->

        <!-- JS Grid Scripts Start-->
        <script>
            (function () {

                var db = {

                    loadData: function (filter) {
                        return this.clients;
                    },

                    insertItem: function (insertingClient) {
                        this.clients.push(insertingClient);
                    },

                    updateItem: function (updatingClient) { },

                    deleteItem: function (deletingClient) {
                        var clientIndex = $.inArray(deletingClient, this.clients);
                        this.clients.splice(clientIndex, 1);
                    }

                };

                window.db = db;

                db.clients = [
                ];

            }());
        </script>
        <script src="assets/js/lib/jsgrid/jsgrid.core.js"></script>
        <script src="assets/js/lib/jsgrid/jsgrid.load-indicator.js"></script>
        <script src="assets/js/lib/jsgrid/jsgrid.load-strategies.js"></script>
        <script src="assets/js/lib/jsgrid/jsgrid.sort-strategies.js"></script>
        <script src="assets/js/lib/jsgrid/jsgrid.field.js"></script>
        <script src="assets/js/lib/jsgrid/fields/jsgrid.field.text.js"></script>
        <script src="assets/js/lib/jsgrid/fields/jsgrid.field.number.js"></script>
        <script src="assets/js/lib/jsgrid/fields/jsgrid.field.select.js"></script>
        <script src="assets/js/lib/jsgrid/fields/jsgrid.field.checkbox.js"></script>
        <script src="assets/js/lib/jsgrid/fields/jsgrid.field.control.js"></script>
        <script>
            $(function () {
                $("#jsGrid").jsGrid({
                    height: "100%",
                    width: "100%",
                    filtering: false,
                    editing: false,
                    inserting: false,
                    sorting: true,
                    paging: true,
                    autoload: true,
                    pageSize: 15,
                    pageButtonCount: 4,
                    deleteConfirm: "Do you really want to delete the client?",
                    controller: db,
                    noDataContent: "目前是空的......",
                    fields: [
                        { name: "barCode", title: "商品条码", type: "text", width: 100 },
                        { name: "productName", title: "商品名称", type: "text", width: 120 },
                        { name: "defaultSellPrice", title: "原价", type: "number", align: "right", width: 30 },
                        { name: "nowSellPrice", title: "现价", type: "number", align: "right", width: 30 }
                    ],
                    rowClick: function (selectRow) {
                        var selectRowData = selectRow.item;
                        window.selected = true;
                        $.each(selectRowData, function (k, v) {
                            $("#" + k).val(v);
                        })
                    }
                });
            });
        </script>
        <!-- JS Grid Scripts End-->

</body>

</html>